#ifdef __cplusplus
extern "C" {
#endif


#include "PluginDependence.h"
#include "Application.h"
#include "Plugin.h"
#include <stdio.h>
#include <malloc.h>
#include <memory.h>
#include <windows.h>

__bvector(PluginDescriptor)

void __begheader(PluginDependence, initialize)
    char * _tName
__begbody
    __voidfun(&(__this(PluginDependence)->mDependences), VectorPluginDescriptor, initialize)

	Application * application = __instance(Application);
    char * name = (char *)malloc(255);
    ::memset(name, '\0', 255);
	::strcat(name, application->mSystemDirectory);
	::strcat(name, "\\");
	::strcat(name, _tName);

    FILE * file = ::fopen(name, "r");

	::memset(name, '\0', 255);
	while (fgets(name, 255, file))
	{
		PluginDescriptor * pluginDescriptor = (PluginDescriptor *)malloc(sizeof(PluginDescriptor));
		pluginDescriptor->mName = name;

		__begfun(&(__this(PluginDependence)->mDependences), VectorPluginDescriptor, pushBack)
			pluginDescriptor
		__endfun

		name = (char *)malloc(255);
		::memset(name, '\0', 255);
	}
	fclose(file);
__endbody

void __begvoid(PluginDependence, startup)
__begbody
    __foreach(&(__this(PluginDependence)->mDependences), VectorPluginDescriptor, __this(PluginDependence), PluginDependencerun)
__endbody

void __voidheader(PluginDependence, run)
    PluginDescriptor * _tPluginDescriptor
__begbody
	Plugin plugin;
	__begfun(&plugin, Plugin, initialize)
		_tPluginDescriptor
	__endfun
	__voidfun(&plugin, Plugin, startup)
__endbody


#ifdef __cplusplus
}
#endif
